{% extends 'stocks/base.html' %}

{% block title %}股票列表 - 股票数据展示系统{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h2><i class="bi bi-list"></i> 股票列表</h2>
    <div>
        <span class="badge bg-secondary">共 {{ page_obj.paginator.count }} 只股票</span>
    </div>
</div>

{% if query %}
<div class="alert alert-info">
    <i class="bi bi-search"></i> 搜索关键词: <strong>"{{ query }}"</strong>
    <a href="{% url 'stock_list' %}" class="btn btn-sm btn-outline-info ms-3">清除搜索</a>
</div>
{% endif %}

<div class="card">
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-hover stock-table">
                <thead class="table-light">
                    <tr>
                        <th>股票代码</th>
                        <th>股票名称</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for stock in page_obj %}
                    <tr>
                        <td><strong>{{ stock.symbol }}</strong></td>
                        <td>{{ stock.name }}</td>
                        <td>
                            <div class="btn-group btn-group-sm">
                                <a href="{% url 'stock_detail' stock.symbol %}" class="btn btn-outline-primary">
                                    <i class="bi bi-eye"></i> 详情
                                </a>
                                <a href="{% url 'daily_data' stock.symbol %}" class="btn btn-outline-success">
                                    <i class="bi bi-bar-chart"></i> 交易
                                </a>
                                <a href="{% url 'financial_data' stock.symbol %}" class="btn btn-outline-info">
                                    <i class="bi bi-calculator"></i> 财务
                                </a>
                                <a href="{% url 'stock_signals' stock.symbol %}" class="btn btn-outline-warning">
                                    <i class="bi bi-bell"></i> 信号
                                </a>
                                <a href="{% url 'stock_visualization' stock.symbol %}" class="btn btn-outline-danger">
                                    <i class="bi bi-graph-up"></i> 可视化
                                </a>
                            </div>
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="3" class="text-center py-4">
                            <i class="bi bi-search display-4 text-muted"></i>
                            <p class="mt-2">没有找到匹配的股票</p>
                            {% if query %}
                            <a href="{% url 'stock_list' %}" class="btn btn-primary mt-2">查看所有股票</a>
                            {% endif %}
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

        {% if page_obj.paginator.num_pages > 1 %}
        <nav aria-label="Page navigation">
            <ul class="pagination justify-content-center">
                {% if page_obj.has_previous %}
                <li class="page-item">
                    <a class="page-link" href="?page=1{% if query %}&q={{ query }}{% endif %}">首页</a>
                </li>
                <li class="page-item">
                    <a class="page-link" href="?page={{ page_obj.previous_page_number }}{% if query %}&q={{ query }}{% endif %}">上一页</a>
                </li>
                {% endif %}

                {% for num in page_obj.paginator.page_range %}
                    {% if page_obj.number == num %}
                    <li class="page-item active">
                        <span class="page-link">{{ num }}</span>
                    </li>
                    {% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %}
                    <li class="page-item">
                        <a class="page-link" href="?page={{ num }}{% if query %}&q={{ query }}{% endif %}">{{ num }}</a>
                    </li>
                    {% endif %}
                {% endfor %}

                {% if page_obj.has_next %}
                <li class="page-item">
                    <a class="page-link" href="?page={{ page_obj.next_page_number }}{% if query %}&q={{ query }}{% endif %}">下一页</a>
                </li>
                <li class="page-item">
                    <a class="page-link" href="?page={{ page_obj.paginator.num_pages }}{% if query %}&q={{ query }}{% endif %}">末页</a>
                </li>
                {% endif %}
            </ul>
        </nav>
        {% endif %}

        <div class="text-muted text-center">
            显示 {{ page_obj.start_index }} - {{ page_obj.end_index }} 条，共 {{ page_obj.paginator.count }} 条记录
        </div>
    </div>
</div>
{% endblock %}
